package com.mjlf.jol;

import org.openjdk.jol.info.ClassLayout;

/**
 * @ClassName JolTest1
 * @auther mjlf
 * @Date 2019/7/16 9:38
 * @Description 性能对比
 */
public class JolTest4 {
    public static A a;

    public static void main(String[] args) {
//        try {
//            Thread.currentThread().sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        long startTime = System.currentTimeMillis();
        a = new A();
        System.out.println("before hash");
        //没有计算hashcode之前的对象头
        System.out.println(ClassLayout.parseInstance(a).toPrintable());

       for(int i = 0; i < 1000000000; i ++){
           a.parse();
       }

        //计算hashcode后
        System.out.println("after hash");
        System.out.println(ClassLayout.parseInstance(a).toPrintable());
        System.out.println("用时：" + (System.currentTimeMillis() - startTime));
    }
}
